/**
 * 根据当前state和指定的action返回一个新的state
 */
import {combineReducers} from 'redux'
import {RECEIVE_USER, RESET_USER} from './action-types'
import storageUtils from '../utils/storageUtils'

/*
用来管理当前登陆用户的reducer函数
 */
const initUser = storageUtils.getUser()

function user(state = initUser, action) {
  switch (action.type) {
    case RECEIVE_USER:
      return action.user
    case RESET_USER:
      return {}
    default:
      return state
  }
}
export default combineReducers({
  user
})